﻿function customizeFields() {
    $('.example5').colorbox();

    var startDate = $('#startDate');
    var endDate = $('#endDate');

    //ToDo: Localize
    var startDateValue = startDate.val();
    startDate.datepicker($.datepicker.regional['en']);
    startDate.datepicker('option', { dateFormat: 'yy-mm-dd' });
    if (startDateValue != null && startDateValue != '')
        startDate.datepicker('setDate', startDateValue);

    var endDateValue = endDate.val();
    endDate.datepicker($.datepicker.regional['en']);
    endDate.datepicker('option', { dateFormat: 'yy-mm-dd' });
    if (endDateValue != null && endDateValue != '')
        endDate.datepicker('setDate', endDateValue);

    validateEvent();
    startDate.datepicker('option', { onSelect: function (dateText, inst) { validator.element(startDate); } });
    endDate.datepicker('option', { onSelect: function (dateText, inst) { validator.element(endDate); } });
}

function AddPropertyValue(baseValueContainerId, firstValueRowId, firstValueContainerId, isTextBox) {
    var firstValueRow = $('#' + firstValueRowId);

    var clonedRow = firstValueRow.clone();

    clonedRow.removeAttr('id');

    var clonedValueContainer = clonedRow.find('#' + firstValueContainerId);

    var firstValueRowParent = firstValueRow.parent(); // parent span
    var valuesCount = firstValueRowParent.children().size();
    var newValueContainerId = baseValueContainerId + valuesCount;
    clonedValueContainer.attr('id', newValueContainerId);
    clonedValueContainer.attr('name', newValueContainerId);

    if (isTextBox)
        clonedValueContainer.value = '';
    else // DropDownList
        clonedValueContainer.selectedIndex = 0;

    firstValueRowParent.append(clonedRow);
}

function RemovePropertyValue() {

}

function getTypeProperties(typeSelectId, propertiesContainerId) {
    var type = $('#' + typeSelectId).val();
    var propertiesContainer = $('#' + propertiesContainerId);

    $.ajax({
        url: '/event/GetTypeAdditionalProperties',
        data: { type: type },
        type: 'post',
        dataType: 'html',
        success: function (data) {
            if (data != null)
                propertiesContainer.html(data);
            else
                alert("Some error happened");
        },
        error: function () {
            alert("Some error happened");
        }
    });
}

function getCategoryProperties(categorySelect) {

    categorySelect = $(categorySelect);

    var category = categorySelect.val();
    var propertiesContainer = categorySelect.nextAll('div:last');

    $.ajax({
        url: '/event/GetCategoryAdditionalProperties',
        data: { category: category },
        type: 'post',
        dataType: 'html',
        success: function (data) {
            if (data != null)
                propertiesContainer.html(data);
            else
                alert("Some error happened");
        },
        error: function () {
            alert("Some error happened");
        }
    });
}